﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Utilidades;
namespace Interfaz
{
    /// <summary>
    /// Interaction logic for LOGS.xaml
    /// </summary>
    public partial class LOGS : Window
    {
        List<string> paraMostrar;
        public LOGS()
        {
            paraMostrar = new List<string>();
            InitializeComponent();
        }
        private void llenarList()
        {
            listBox1.Items.Clear();
            for (int i = 0; i < paraMostrar.Count; i++)
            {
                listBox1.Items.Add(paraMostrar[i]);
            }
        }
        private void recuperar(string ruta)
        {
            try
            {
                paraMostrar = Archivo.leer(ruta);
                llenarList();
                labelError.Content = "";
            }
            catch (Exception ex)
            {
                
                throw ex;
            }
            
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                recuperar("LOGS/EntradaUsuario.txt");
            }
            catch (Exception ex)
            {
                
                labelError.Content = ex.Message;
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                recuperar("LOGS/SistemaBloqueado.txt");
            }
            catch (Exception ex)
            {
                
                labelError.Content = ex.Message;
            }
            
            
        }

        private void buttonBuscar_Click(object sender, RoutedEventArgs e)
        {
            listBox1.Items.Clear();
            if (datePicker1.SelectedDate != null)
            {
                string date = datePicker1.SelectedDate.Value.ToShortDateString();
                bool entro = false;
                for (int i = 0; i < paraMostrar.Count; i++)
                {
                    if (paraMostrar[i].Contains(date))
                    {
                        labelError.Content = "";
                        listBox1.Items.Add(paraMostrar[i]);
                        entro = true;
                    }
                }
                if (!entro)
                    labelError.Content = "No se encontraron resultados";
            }
            else
                labelError.Content = "Debe seleccionar una fecha";
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                recuperar("LOGS/Venta.txt");
            }
            catch (Exception ex)
            {

                labelError.Content = ex.Message;
            }
        }
    }
}
